package com.sokal.easycare.modules.forum.entity;

import java.util.Date;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.sokal.easycare.common.config.Global;
import com.sokal.easycare.common.persistence.DataEntity;
import com.sokal.easycare.common.utils.StringUtils;
import com.sokal.easycare.modules.sys.entity.MainUser;

/**
 * 论坛Entity
 * @author lihaipei
 * @version 2017-05-07
 */
public class Forum extends DataEntity<Forum> {
	
	private static final long serialVersionUID = 1L;
	private String title;		// 标题
	private String content;		// 内容
	private Integer browseQuantity;		// 浏览量
	private Integer repliesCount; //回帖数量
	private Date latestReplyDate; //最后回复时间
	private ForumModule forumModule; //所属板块
	
	public Forum() {
		super();
		this.browseQuantity = 0;
		this.repliesCount = 0;
	}

	public Forum(String id){
		super(id);
	}

	public Forum(ForumModule forumModule){
		super();
		this.forumModule = forumModule;
	}

	@Length(min=0, max=255, message="标题长度必须介于 0 和 255 之间")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	@Length(min=0, max=4000, message="内容长度必须介于 0 和 4000 之间")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	public Integer getBrowseQuantity() {
		return browseQuantity;
	}

	public void setBrowseQuantity(Integer browseQuantity) {
		this.browseQuantity = browseQuantity;
	}

	public Integer getRepliesCount() {
		return repliesCount;
	}

	public void setRepliesCount(Integer repliesCount) {
		this.repliesCount = repliesCount;
	}

	public Date getLatestReplyDate() {
		return latestReplyDate;
	}

	public void setLatestReplyDate(Date latestReplyDate) {
		this.latestReplyDate = latestReplyDate;
	}
	
	@NotNull(message="论坛板块不能为空")
	public ForumModule getForumModule() {
		return forumModule;
	}

	public void setForumModule(ForumModule forumModule) {
		this.forumModule = forumModule;
	}

	public MainUser getCreator() {
		if (createBy != null) {
			if (StringUtils.isNotBlank(createBy.getPortraitPhoto())) {
				if (!createBy.getPortraitPhoto().startsWith("http:")) {
					createBy.setPortraitPhoto(Global.getConfig("fastdfs_file_url")+createBy.getPortraitPhoto());
				}
			}
		}
		return createBy;
	}

}